$Head = "<html><head><style>"
$Head +="BODY{background-color:white;font-family:Verdana,sans-serif; font-size: x-small;}"
$Head +="TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse; width: 100%;}"
$Head +="TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:SteelBlue;color:white;padding: 5px; font-weight: bold;text-align:left;}"
$Head +="TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:white; padding: 2px;}"
$Head +="</style></head><body>"

$OutFile = "Netlogon.log.csv"
if(Test-Path $OutFile) { Remove-Item $OutFile }

$DCs = "uk01padc006","uk01padc007","uk01padc004","uk01padc304","uk01padc305","uk70padc001","uk70padc102","uk70padc201","uk70padc202","uk75padc001","uk75padc002"


$Today = get-date -Format MM/dd

$Info = "<p>Netlogon.log parsed from: "
foreach($DC in $DCs) {
	$Info += "$DC, "
	$Netlogon = Get-Content "\\$DC\c$\windows\debug\netlogon.log"
	foreach($Line in $Netlogon) {
		if($Line.StartsWith($Today) -and $Line.Contains("NO_CLIENT_SITE")) {
			$Arr = $Line.Split()
			$Out = (($Arr[4])+","+($Arr[5]))
			Add-Content -Path $OutFile (($Arr[4])+","+($Arr[5]))
		}
	}
}
$Info+= "</p>"
$Table = "<table><tr><th>Client</th><th>IP</th></tr>"
ConvertFrom-Csv (Get-Content $OutFile | sort | select -unique) -Header Client,IP | foreach-object { $Table += ("<tr><td>"+$_.Client+"</td><td>"+$_.IP+"</td></tr>") }
$Table += "</table></body></html>"


$SmtpClient = New-Object system.net.mail.smtpClient 
$MailMessage = New-Object system.net.mail.mailmessage 
$SmtpClient.Host = "smtp.acegroup.com" 
$mailmessage.from = "netlogon.report@acegroup.com" 
$mailmessage.To.add("sam.mcgeown@acegroup.com") 
$mailmessage.To.add("teresa.reid@ACEGroup.com") 
$mailmessage.Subject = "Netlogon Client IP Mapping Report" 
$MailMessage.IsBodyHtml = 1 
$mailmessage.Body = ($Head+$Info+$Table)
$smtpclient.Send($mailmessage)
